//
//  TTAPI+Login.swift
//  TTBLL
//
//  Created by Toj on 4/16/21.
//

import Foundation

extension TTAPIRequest.API {
    
    /// 获取AppSecret
    static var secret: TTAPIRequest.API {
        return TTAPIRequest.API(rawValue: "/user/secret")
    }
    
    /// 登录
    static var login: TTAPIRequest.API {
        return TTAPIRequest.API(rawValue: "/user/login")
    }
    
    /// 验证码登录
    static var validateLogin: TTAPIRequest.API {
        return TTAPIRequest.API(rawValue: "/user/c/v1.0/validateLogin")
    }
    
    /// token登录
    static var tokenLogin: TTAPIRequest.API {
        return TTAPIRequest.API(rawValue: "/user/tokenLogin")
    }
    
    /// 手机号登录 获取验证码
    static var getLoginCode: TTAPIRequest.API {
        return TTAPIRequest.API(rawValue: "/pad/user/code/get")
    }
    
    /// 手机号+验证码 登录
    static var loginCode: TTAPIRequest.API {
        return TTAPIRequest.API(rawValue: "/pad/user/phone/login")
    }
    
    /// 修改密码 --> 获取验证码
    static var getVerifyCode: TTAPIRequest.API {
        return TTAPIRequest.API(rawValue: "/user/sendVerifyCode")
    }
    
    /// 修改密码 --> 验证验证码
    static var checkVerifyCode: TTAPIRequest.API {
        return TTAPIRequest.API(rawValue: "/user/checkVerifyCode")
    }
    
    // 修改密码
    static var updateLoginPassword: TTAPIRequest.API {
        return TTAPIRequest.API(rawValue: "/user/modifyByPhone")
    }
}

extension TTAPI.Request {
    
    internal static func secret(completion:((_ response:TTResponse<String>)->())?) {
        
        general(api: .secret, model: String.self, hearders: .secret, completion: completion)
    }
    
    static func login(_ parameters:[String: Any]? = nil,
                      completion:((_ response:TTResponse<TTLoginModel>)->())?) {
        
        general(api: .login, model: TTLoginModel.self, parameters: parameters, completion: completion)
    }
}
